package cn.itheima.job;

import cn.itheima.health.resources.DateUtils;
import cn.itheima.health.service.OrderSettingService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component("orderSettingCleanObject")
public class OrderSettingCleanObject {

    @Reference
    private OrderSettingService orderSettingService;


    public void deleteOrderSettingByDate(){
        System.out.println("-----quartz  is  running ----");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date curDate = new Date();
        Date lastDayOfMonth = DateUtils.getLastDayOfMonth(curDate);
        String date = sdf.format(curDate);
        String lastDay = sdf.format(lastDayOfMonth);
        System.out.println(lastDay);
        if ("2020-08-31".equals(lastDay)){
            System.out.println("-----clean orderSetting  is  running ----");
            orderSettingService.deleteOrderSettingByDate(curDate);
            System.out.println("清除历史预约记录成功");
        }
    }
}
